<?php

namespace App\Admin\Forms\Customer;

use App\Enums\OptionType;
use App\Enums\SalePerformanceType;
use App\Models\Customer;
use App\Services\OptionService;
use App\Services\SaleService;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Http\JsonResponse;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;

class SalePerformanceForm extends Form implements LazyRenderable
{
    use LazyWidget;

    /**
     * Handle the form request.
     *
     * @param array $input
     *
     * @return JsonResponse
     */
    public function handle(array $input): JsonResponse
    {
        app(SaleService::class)->addPerformance($this->payload['id'], $input);
        return $this
            ->response()
            ->success(trans('admin.processed_successfully'))
            ->refresh();
    }

    /**
     * Build a form here.
     */
    public function form()
    {
        //业绩信息
        $this->select('payment_option_id', trans('sale-performance.fields.payment_option_id'))->required()->options(OptionService::getOption(OptionType::PAYMENT));
        $this->text('disease',trans('sale-performance.fields.disease'))->maxLength(100);

        $this->number('money', trans('sale-performance.fields.money'))->min(1)->max(999999)->required();

        //$this->text('pay_number', trans('sale-performance.fields.pay_number'))->maxLength(100)->required();

        $this->select('type', trans('sale-performance.fields.type'))->options([
            SalePerformanceType::DEPOSIT => SalePerformanceType::getDescription(SalePerformanceType::DEPOSIT),
            SalePerformanceType::FULL => SalePerformanceType::getDescription(SalePerformanceType::FULL),
        ])->required();

        $this->text('medication', trans('sale-performance.fields.medication'));
        $this->text('treatment', trans('sale-performance.fields.treatment'));
        $this->text('bill', trans('sale-performance.fields.bill'));
        $this->textarea('symptom', trans('sale-performance.fields.symptom'));
        $this->datetime('consultation',trans('sale-performance.fields.consultation'));
        $this->multipleImage('pay_images', trans('sale-performance.fields.pay_images'))->move('images/' . date('Y') . '/' . date('m') . '/' . date('d'))->uniqueName()->autoUpload();
        $this->textarea('remark', trans('sale-performance.fields.remark'));
    }

}
